#ifndef VIDEO_DECODER_H_
#define VIDEO_DECODER_H_

#include <theora/theora.h>
#include <theora/theoradec.h>
#include "def.h"
#include <QtCore>

class VideoDecoder : public QThread
{
	Q_OBJECT

public:
	VideoDecoder(void);
	~VideoDecoder(void);

	void reset(PacketList *headers);
	int decode(PacketList *packets);
	inline const unsigned char * rawData() { return m_lpRawImageData; }

signals:
	void onDecoded(const int width, const int height);

protected:
	bool m_bExit;
	QQueue<PacketList*> m_listPending;

	th_info *m_thInfo;
	th_setup_info *m_thSetupInfo;
	th_comment *m_thComment;
	th_dec_ctx *m_thDecContext;
	unsigned char *m_lpRawImageData;

	void yuv444_to_rgb(th_ycbcr_buffer buffer, unsigned char *rgb);
	void run();
};

#endif // VIDEO_DECODER_H_
